<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="title" value="智慧大棚管理"/>
<%@ include file="../common/header.jsp" %>
<div class="main-content">
    <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
        <h1 class="h2">${title}</h1>
        <!-- 添加种植大棚按钮 -->
        <button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addGreenhouseModal">
            <i class="fa-solid fa-plus-circle"></i> 添加种植大棚
        </button>

        <!-- 添加种植大棚模态框 -->
        <div class="modal fade" id="addGreenhouseModal" tabindex="-1">
            <div class="modal-dialog">
                <div class="modal-content">
                    <form id="addGreenhouseForm" method="post" action="${pageContext.request.contextPath}/production/addGreenhouse">
                        <div class="modal-header">
                            <h5 class="modal-title">添加种植大棚</h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                        </div>
                        <div class="modal-body">
                            <div class="mb-3">
                                <label class="form-label">大棚名称</label>
                                <input type="text" class="form-control" name="baseName" required>
                            </div>
                            <div class="mb-3">
                                <label class="form-label">位置</label>
                                <input type="text" class="form-control" name="location" required>
                            </div>
                            <div class="mb-3">
                                <label class="form-label">负责人</label>
                                <input type="text" class="form-control" name="manager">
                            </div>
                            <div class="mb-3">
                                <label class="form-label">种植数量</label>
                                <input type="number" class="form-control" name="plantingCount">
                            </div>
                            <div class="mb-3">
                                <label class="form-label">联系方式</label>
                                <input type="text" class="form-control" name="contact">
                            </div>
                            <div class="mb-3">
                                <label class="form-label">面积(亩)</label>
                                <input type="number" step="0.01" class="form-control" name="area">
                            </div>
                            <div class="mb-3">
                                <label class="form-label">描述</label>
                                <input type="text" class="form-control" name="description">
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="table-responsive">
        <table class="table table-bordered table-hover">
            <thead class="table-light">
                <tr>
                    <th>大棚ID</th>
                    <th>所属基地名称</th>
                    <th>产地</th>
                    <th>负责人</th>
                    <th>种植次数</th>
                    <th>联系方式</th>
                    <th>面积(亩)</th>
                    <th>备注</th>
                    <th>创建时间</th>
                </tr>
            </thead>
            <tbody>
                <c:forEach var="base" items="${baseList}">
                    <tr>
                        <td>${base.baseId}</td>
                        <td>${base.baseName}</td>
                        <td>${base.location}</td>
                        <td>${base.manager}</td>
                        <td>${base.plantingCount}</td>
                        <td>${base.contact}</td>
                        <td>${base.area}</td>
                        <td>${base.description}</td>
                        <td>${base.createTime}</td>
                    </tr>
                </c:forEach>
            </tbody>
        </table>
    </div>


</div>
<%@ include file="../common/footer.jsp" %> 
<script>
$(function() {
    $('#addGreenhouseForm').on('submit', function(e) {
        e.preventDefault();
        $.ajax({
            url: '${pageContext.request.contextPath}/production/addGreenhouse',
            type: 'POST',
            data: $(this).serialize(),
            success: function(res) {
                $('#addGreenhouseModal').modal('hide');
                location.reload();
            },
            error: function() {
                alert('保存失败，请重试');
            }
        });
    });
});
</script> 